package logic

import (
	"context"
	"develop/model/mysql"
	"develop/usersrpc/internal/svc"
	"develop/usersrpc/usersrpc"
	"errors"

	"github.com/zeromicro/go-zero/core/logx"
)

type VideoUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewVideoUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *VideoUpdateLogic {
	return &VideoUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *VideoUpdateLogic) VideoUpdate(in *usersrpc.VideoUpdateRequest) (*usersrpc.VideoUpdateResponse, error) {
	// todo: add your logic here and delete this line
	var videoId mysql.Video_Info
	err := videoId.FindVideoId(mysql.DB, in.VideoId)
	if err != nil {
		return nil, err
	}
	if videoId.ID == 0 {
		return nil, errors.New("视频不存在")
	}
	info := &mysql.Video_Info{
		Video_Status: int(in.VideoStatus),
	}
	err = info.UpdateInfo(mysql.DB, in.VideoId)
	if err != nil {
		return nil, errors.New("修改失败")
	}
	return &usersrpc.VideoUpdateResponse{
		VideoId: int64(videoId.ID),
	}, nil
}
